#测试我的项目页面
import time
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

from common.Untils import WJDriver
from selenium.webdriver.common.by import By
from tests import WJLogin

class WJProject:
    url = ""
    driver = ""

    def __init__(self):
        #WJLogin.WJLogin().LoginSuccess()
        self.url = "http://8.155.1.153:8081/project"
        self.driver = WJDriver.driver
        self.driver.get(self.url)
        WJDriver.Login()
        #点击我的项目
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(2)").click()
    # 进行页面元素的查找检查
    def TestByProject(self):
        # 检查页面标题元素
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > div > span")
        # 检查新建按钮
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button")
        # 检查搜索框
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input")
        # 检查搜索按钮
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button > span > svg")
        print("元素正常")


    # 功能测试
    def TestByProjectFunction(self):
        # 创建显示等待类对象
        wait = WebDriverWait(self.driver,10)

        self.driver.maximize_window()
        #测试场景一：新建点击问卷调查填写内容后点击保存提示保存成功
        #点击新建
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
        #点击问卷调查
        self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(8) > div > div > ul > li:nth-child(1) > span").click()
        #输入内容
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div.header > div.header-content > div.sc-aXZVg.LyTMt.title.quill-container.not-focus > div > pre > div.ql-editor > p").send_keys(WJDriver.name)
        self.driver.find_element(By.CLASS_NAME, "menu-group-item").click()
        #sleep(1)
        #点击保存
        sleep(1)
        #wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span")))
        self.driver.find_element(By.CSS_SELECTOR,"#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span").click()
        # self.driver.back()
        # self.driver.back()
        #跳转到我的项目
        wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button")))
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button").click()
        print("问卷调查新建成功！")
        ##################################################################################################################
        #测试场景二：新建点击在线考试填写内容后点击保存提示保存成功
        # 点击新建
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
        # 点击在线考试
        self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(9) > div > div > ul > li:nth-child(2) > span").click()
        # 输入内容
        time.sleep(1)
        #输入标题跟点击左边的单选题
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div.header > div.header-content > div.sc-aXZVg.LyTMt.title.quill-container.not-focus > div > pre > div.ql-editor > p").send_keys(WJDriver.name)
        time.sleep(1)
        self.driver.find_element(By.CLASS_NAME,"menu-group-item").click()
        #time.sleep(1)
        # 点击保存
        sleep(1)
        #wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm")))
        self.driver.find_element(By.CSS_SELECTOR,"#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm").click()
        # self.driver.back()
        # self.driver.back()
        #点击项目跳转到我的项目
        sleep(1)
        wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button")))
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button").click()
        print("在线考试新建成功！")
        #########################################################################################################################
        #测试场景四：新建点击通过文本导入，填写完成后进入编辑页面编辑完成后点击保存，在项目搜索框中搜索刚刚创建的项目
        # 点击新建
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
        sleep(1)
        # 点击通过文本导入
        self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(9) > div > div > ul > li:nth-child(4) > span").click()
        # 点击创建项目------到这一步就不动没反应
        #sleep(1)
        #self.driver.execute_script("document.querySelector('body > div:nth-child(11) > div > div.ant-drawer-content-wrapper > div > div > div.ant-drawer-header > div.ant-drawer-extra > div > div:nth-child(2) > button').click()")
        #wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div:nth-child(11) > div > div.ant-drawer-content-wrapper > div > div > div.ant-drawer-header > div.ant-drawer-extra > div > div:nth-child(2) > button")))
        #self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(11) > div > div.ant-drawer-content-wrapper > div > div > div.ant-drawer-header > div.ant-drawer-extra > div > div:nth-child(2) > button").click()
        # 点击保存
        #sleep(1)
        #wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span")))
        #self.driver.find_element(By.CSS_SELECTOR,"#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span").click()
        # 点击项目跳转到我的项目
        #sleep(1)
        #wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button")))
        #self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button").click()
        self.driver.back()
        #sleep(1)
        self.driver.back()
        #sleep(1)
        self.driver.back()
        #sleep(5)
        print("文本导入新建成功！")
        #########################################################################################################################
        #测试点击新建模板导入
        # 点击新建
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
        # 点击通过模板导入
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div:nth-child(9) > div > div > ul > li:nth-child(5) > span").click()
        #点击取消
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div:nth-child(10) > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-footer > button.ant-btn.ant-btn-default").click()
        print("模板导入成功")
        ############################################################################################################################################
        #测试新建文件夹，并搜索是否存在
        # 点击新建
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
        # 点击通过模板导入
        #sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div:nth-child(9) > div > div > ul > li:nth-child(6) > span").click()
        #输入文件夹名称
        wjj=WJDriver.name
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#name").send_keys(wjj)
        #点击确定
        #sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div:nth-child(10) > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-footer > button.ant-btn.ant-btn-primary").click()
        #sleep(1)
        #在输入框输入刚刚创建的文件夹，点击确定
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input").send_keys(wjj)
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button").click()
        print("文件夹创建成功")

        sleep(2)
        print("我的项目页面全部正常..............")



        #self.driver.quit()
# project=WJProject()
# project.TestByProject()
# project.TestByProjectFunction()



